JAVA - The Beginnings by Ralph Lecessi

JAVA - The Beginnings by Ralph Lecessi

Author:Ralph Lecessi [Lecessi, Ralph]
Language: eng
Format: azw3, pdf
Publisher: Ralph Lecessi Incorporated
Published: 2017-08-23T04:00:00+00:00


private static String nameList = "";

Field nameList is declared private so that it is only accessible inside objects of class Name .

Section 3 - Static Field Initialization

Static fields must be initialized during declaration. They should not be initialized inside a constructor because static fields may be utilized when no objects have been created.

The following version of the Name class does not initialize static field nameList during declaration. Initialization is instead performed inside the constructor. The main program then uses the public getNameList method to obtain the name list before any objects are created, and therefore, before the constructor is called. Since String fields are initialized by default to null in Java, the accessor returns a null reference. When the main program attempts to call the String class’s length method using the null reference, a NullPointerException is thrown.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.